package utils

import (
	"container/list"
	"os"
	"path/filepath"
)

func GetExePath() string {
	dir, _ := os.Executable()
	exPath := filepath.Dir(dir)

	return exPath
}

//************************栈操作******************************************
type Stack struct {
	list *list.List
}

func NewStack() *Stack {
	list := list.New()

	return &Stack{list}
}

func (stack *Stack) Push(value interface{}) {
	stack.list.PushBack(value)
}

func (stack *Stack) Pop() interface{} {
	e := stack.list.Back()
	if e != nil {
		stack.list.Remove(e)
		return e.Value
	}

	return nil
}

func (stack *Stack) Peak() interface{} {
	e := stack.list.Back()
	if e != nil {
		return e.Value
	}

	return nil
}

func (stack *Stack) Len() int {
	return stack.list.Len()
}

func (stack *Stack) Empty() bool {
	return stack.list.Len() == 0
}

//***********************反向操作****************************************
func ByteArrayReverse(a []byte) []byte {
	tl := len(a)
	t := make([]byte, tl)
	for i := 0; i < tl; i++ {
		t[i] = a[tl-i-1]
	}

	return t
}
